var oldpassword = null;
var newpassword = null;
var rnewpassword = null;
var saveBtn = null;

$(function(){
	oldpassword = $("#oldpassword");
	newpassword = $("#newpassword");
	rnewpassword = $("#rnewpassword");
	saveBtn = $("#save");
	
	oldpassword.next().html("*");
	newpassword.next().html("*");
	rnewpassword.next().html("*");
	
	oldpassword.on("blur",function(){
		
		$.ajax({
			type:"GET",
			url:path+"/user/pwd.json",
			data:{oldpassword:oldpassword.val() },
			dataType:"json",
			success:function(data){
				if(data.dos == "true"){ 
					validateTip(oldpassword.next(),{"color":"green"},"112",true);
				}else if(data.dos == "false"){//���������벻��ȷ
					validateTip(oldpassword.next(),{"color":"red"},imgNo + "11",false);
				}else if(data.dos == "sessionerror"){
					validateTip(oldpassword.next(),{"color":"red"},imgNo + " 22",false);
				}
			},
			error:function(data){
		
				validateTip(oldpassword.next(),{"color":"red"},imgNo + " 2323",false);
			}
		});
		
		
	}).on("focus",function(){
		validateTip(oldpassword.next(),{"color":"#666666"},"* ������ԭ����",false);
	});
	
	newpassword.on("focus",function(){
		validateTip(newpassword.next(),{"color":"#666666"},"* ���볤�ȱ����Ǵ���6С��20",false);
	}).on("blur",function(){
		if(newpassword.val() != null && newpassword.val().length > 6
				&& newpassword.val().length < 20 ){
			validateTip(newpassword.next(),{"color":"green"},imgYes,true);
		}else{
			validateTip(newpassword.next(),{"color":"red"},imgNo + " �������벻��Ϲ淶������������",false);
		}
	});
	
	
	rnewpassword.on("focus",function(){
		validateTip(rnewpassword.next(),{"color":"#666666"},"* ������������һ�µ�����",false);
	}).on("blur",function(){
		if(rnewpassword.val() != null && rnewpassword.val().length > 6
				&& rnewpassword.val().length < 20 && newpassword.val() == rnewpassword.val()){
			validateTip(rnewpassword.next(),{"color":"green"},imgYes,true);
		}else{
			validateTip(rnewpassword.next(),{"color":"red"},imgNo + " �����������벻һ�£�����������",false);
		}
	});
	
	
	saveBtn.on("click",function(){
		oldpassword.blur();
		newpassword.blur();
		rnewpassword.blur();
		if( newpassword.attr("validateStatus") == "true"
			&& rnewpassword.attr("validateStatus") == "true"){
			if(confirm("ȷ��Ҫ�޸����룿")){
				$("#userForm").submit();
			}
		}
		
	});
});